import 'package:flutter/material.dart';
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;

class InteractiveDemo extends StatefulWidget {
	@override
	State<StatefulWidget> createState() {
		return InteractiveDemoState();
	}
}

class InteractiveDemoState extends State<InteractiveDemo> {

	bool _isFavorite = true;
	int _favoriteCount = 31;

	@override
	Widget build(BuildContext context) {
		return Scaffold(
			appBar: AppBar(title: Text("AssetsDemo"),
			),
			body: Column(
				children: <Widget>[
					FavoriteButton(),
				],
			),
		);
	}


}

class FavoriteButton extends StatefulWidget {
	@override
	State<StatefulWidget> createState() {
		return FavoriteButtonState();
	}
}

class FavoriteButtonState extends State<FavoriteButton> {

	bool _isFavorite = true;
	int _favoriteCount = 31;

	@override
	Widget build(BuildContext context) {
		return _createFavoriteButton();
	}

	Widget _createFavoriteButton() {
		return new Row(
			children: <Widget>[
				IconButton(
					icon: Icon(
						this._isFavorite ? Icons.star : Icons.star_border,
						color: Colors.red[300],
					),
					onPressed: _toggleFavorite,
				),
				Text("$_favoriteCount")
			],
		);
	}

	void _toggleFavorite() {
		setState(() {
			_isFavorite = !_isFavorite;
			if (_isFavorite) {
				_favoriteCount += 1;
			} else {
				_favoriteCount -= 1;
			}
		});
	}

}
